﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 药品信息管理
{
    public partial class YP_JBGL : DevComponents.DotNetBar.Office2007Form
    {
        DataTable dt=new DataTable();
        public YP_JBGL()
        {
            InitializeComponent();
        }

        #region 显示数据
        private void YP_LBGL_Load(object sender, EventArgs e)
        {
            
                try
                {
                    using (SqlConnection con = new SqlConnection(SQL.connectDB))
                    {

                        SqlCommand sc = con.CreateCommand();//使用connection对象创建SqlCommand对象
                        SqlDataAdapter da = new SqlDataAdapter();//实例化sqldataadpte
                        SqlCommand cmd1 = new SqlCommand("SELECT * FROM ZD_YPJB", con);//sql语句
                        da.SelectCommand = cmd1;//设置为已实例化SqlDataAdapter的查询命令
                        da.Fill(dt);
                        dataGridViewX1.DataSource = dt;
                        dataGridViewX1.Columns[0].HeaderText = "编码";
                        dataGridViewX1.Columns[1].HeaderText = "级别名称";
                        dataGridViewX1.Columns[2].HeaderText = "标记[1:使用/0:停用]";
                        dataGridViewX1.Columns[1].Width = 180;
                        dataGridViewX1.Columns[2].Width = 180;
                        //dataGridViewX1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader;//自动根据内容调整列宽
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }
        #endregion

        #region 保存
        private void SAVE_Click(object sender, EventArgs e)
        {
           
                if (dt != null)
                {
                    try
                    {
                        using (SqlConnection con = new SqlConnection(SQL.connectDB))
                        {
                            SqlDataAdapter uda = new SqlDataAdapter("select * from ZD_YPJB", con);
                            SqlCommandBuilder scb = new SqlCommandBuilder(uda);
                            uda.Update(dt);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                MessageBox.Show("保存成功！", "系统提示");
            }
        #endregion

        #region 增加
        private void ADD_Click(object sender, EventArgs e)
        {
            dataGridViewX1.CurrentCell = this.dataGridViewX1.Rows[this.dataGridViewX1.Rows.Count - 1].Cells[1];
            dataGridViewX1.CurrentRow.Cells[0].Value=dataGridViewX1.Rows.Count;
        }
        #endregion

        #region 删除
        private void DELETE_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridViewX1.Rows.Remove(dataGridViewX1.Rows[dataGridViewX1.CurrentCell.RowIndex]);
            }
            catch { }

        }
        #endregion

    
    }
           
}


